package com.lovesher.payment.service.service.impl;

import com.lovesher.payment.common.enums.SchedulePayTaskStatus;
import com.lovesher.payment.common.resposity.bean.PaymentSerial;
import com.lovesher.payment.common.service.PaymentSerialService;
import com.lovesher.payment.service.resposity.dao.PaymentSerialDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * 
 * PaymentSerialService
 * 
 **/
@Service("paymentSerialService")
public class PaymentSerialServiceImpl extends BaseServiceImpl<PaymentSerial, PaymentSerialDao> implements PaymentSerialService{

	@Resource
	private PaymentSerialDao paymentSerialDao;

	@Override
	public PaymentSerialDao getDao() {
		return paymentSerialDao;
	}

	@Override
	public List<PaymentSerial> getListByStatus(Integer taskStatus, int status, Integer cpos, Integer size,
			List<String> paymentMethods, Integer secTime) {
		List<PaymentSerial> resList = paymentSerialDao.getListByStatus(taskStatus, status,
				cpos, size, paymentMethods, secTime);
		if (resList == null) {
			resList = new ArrayList<PaymentSerial>();
		}

		for (PaymentSerial paymentSerial : resList) {
			if (paymentSerial.getTaskStatus() == SchedulePayTaskStatus.TASK_1000.getValue()) {
				paymentSerial.setTaskStatus(SchedulePayTaskStatus.TASK_1001.getValue());
				
				PaymentSerial the = new PaymentSerial();
				the.setId(paymentSerial.getId());
				the.setTaskStatus(SchedulePayTaskStatus.TASK_1001.getValue());
				paymentSerialDao.update(the);
			} else {
				paymentSerial.setTaskStatus(SchedulePayTaskStatus.DONE.getValue());
			}
		}

		return resList;
	}

}